#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

//暴力法
class Solution{
public:
    int removeElement(vector<int>& nums, int val) {
        int n = nums.size();
        for(int i = 0; i < n; i ++){
            if(nums[i] == val){
                for(int j = i + 1; j < n; j++){
                    nums[j - 1] = nums[j];
                }
                i--;
                n--;
            }
        }
        return n;
    }
};

//双指针法
class Solution{
public:
    int removeElement(vector<int>& nums, int val) {
        int fast = 0, low = 0, n = nums.size();
        for(fast; fast < n; fast++){
            if(nums[fast] != val){
                nums[low++] = nums[fast];
            }
        }
        return low;
    }
};

int main()
{
    Solution s;
    vector<int> nums = {0,1,2,2,3,0,4,2};
    int val = 2;

    cout << s.removeElement(nums, val) << endl;

    return 0; 
}